package my;

import my.tree.AVLTree;
import my.tree.BST;
import my.tree.RBTree;
import my.printer.BinaryTrees;

/**
 * <p>
 * 测试
 * </p>
 *
 * @author AJun
 * @since 2020/8/13
 */
public class Main09 {

    public static void main(String[] args) {
        // testBST();
        // testAVL();
        // testRBTreeAdd();
        testRBTreeRemove();
    }

    static void testRBTreeRemove() {
        Integer[] elements = {55, 87, 56, 74, 96, 22, 62, 20, 70, 68, 90, 50};
        RBTree<Integer> rbTree = new RBTree<>();
        for (Integer e : elements) {
            rbTree.add(e);
        }

        BinaryTrees.println(rbTree);

        // 删除
        for (Integer e : elements) {
            rbTree.remove(e);
            System.out.println("---------------------------------------------");
            System.out.println("[" + e + "]");
            BinaryTrees.println(rbTree);
        }
    }

    static void testRBTreeAdd() {
        Integer[] elements = {55, 87, 56, 74, 96, 22, 62, 20, 70, 68, 90, 50};
        RBTree<Integer> rbTree = new RBTree<>();
        for (Integer e : elements) {
            rbTree.add(e);
        }
        BinaryTrees.println(rbTree);
    }

    static void testAVL() {
        Integer[] elements = {99, 18, 90, 59, 98, 20, 51, 23, 79, 82, 49, 93, 1};
        BST<Integer> avlTree = new AVLTree<>();
        for (Integer e : elements) {
            avlTree.add(e);
        }
        BinaryTrees.println(avlTree);
        avlTree.remove(51);
        BinaryTrees.println(avlTree);
    }

    static void testBST() {
        Integer[] elements = {67, 52, 92, 96, 53, 95, 13, 63, 34, 82, 76, 54, 9, 68, 39};

        BST<Integer> bst = new BST<>();
        for (Integer e : elements) {
            bst.add(e);
        }
        BinaryTrees.println(bst);
        bst.remove(39);
        System.out.println("----------------------------------------------------------");
        BinaryTrees.println(bst);
        System.out.println("二叉搜索树高度 => " + bst.height());
        System.out.println("二叉搜索树高度 => " + bst.heightLevelOrder());
        bst.preorder((e) -> System.out.print(e + "\t"));
        System.out.println();
        bst.inorder((e) -> System.out.print(e + "\t"));
        System.out.println();
        bst.postorder((e) -> System.out.print(e + "\t"));
        System.out.println();
        bst.levelOrder((e) -> System.out.print(e + "\t"));
    }

}
